package it.isa.demo.controller;

import it.isa.demo.entity.JpaBook;
import it.isa.demo.mapper.JpaBookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Corgile
 * @date 2022-02-27
 */
@RestController
@RequestMapping(value = "jpa_book")
public class JpaBookController {

	@Autowired
	private JpaBookMapper bookMapper;

	@GetMapping(value = "get/{id}")
	public JpaBook getBookById(@PathVariable(name = "id") Integer id) {
		return this.bookMapper.findJpaBookByBookId(id);
	}

	@GetMapping(value = "all")
	public List<JpaBook> getAll() {
		return this.bookMapper.findAll();
	}

	@GetMapping(value = "between/{l}-{r}")
	public List<JpaBook> findBetween(
			@PathVariable(name = "l") Integer l, @PathVariable(name = "r") Integer r) {
		return this.bookMapper.findByBookIdGreaterThanAndBookIdLessThan(l, r);
	}

	@GetMapping(value = "contains/{token}")
	public List<JpaBook> findContains(@PathVariable(name = "token") String token) {
		System.out.println(token);
		return this.bookMapper.findByNameContains(token);
	}

}
